<template>
  <n-h1>GNN 关联强度</n-h1>
  <n-data-table :columns="cols" :data="list" />
</template>

<script setup>
import { ref } from 'vue'
const list = ref([])
const cols = [
  { title: '代码', key: 'code' },
  { title: 'GNN Score', key: 'gnn_score', sorter: 'desc' }
]

const ws = new WebSocket('ws://localhost:8001/ws/tick')
ws.onmessage = (ev) => {
  const d = JSON.parse(ev.data)
  if (d.gnn_score !== undefined) {
    const idx = list.value.findIndex(i => i.code === d.code)
    idx >= 0 ? list.value[idx].gnn_score = d.gnn_score : list.value.push(d)
  }
}
</script>
